package com.example.jin.handlerthread;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btn_start, btn_end;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn_start = (Button) findViewById(R.id.start);
        btn_start.setOnClickListener(new StartOnClickListener());
        btn_end = (Button) findViewById(R.id.end);
        btn_end.setOnClickListener(new EndOnClickListener());
    }

    Handler handler = new Handler();
    class StartOnClickListener implements Button.OnClickListener{
        @Override
        public void onClick(View v) {
            handler.post(updateThread);
        }
    }

    class EndOnClickListener implements Button.OnClickListener{
        @Override
        public void onClick(View v) {

        }
    }

    final Runnable updateThread = new Runnable() {
        @Override
        public void run() {
            System.out.println("updateThread");
            handler.postDelayed(updateThread, 2000);
        }
    };

}
